package com.jike.buyi.system.index.controller;


import com.jike.buyi.contents.WebContens;
import com.jike.buyi.system.index.domain.UserVo;
import com.jike.buyi.system.index.service.IndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Slf4j
@Controller
public class IndexController {
    @Autowired
    private IndexService indexService;

    @RequestMapping("/index")
    public String index(){
        return "/system/index/index";
    }

    /**
     * @param username
     * @param password
     * @return 0：用户名或密码错误 1：登录成功  2：用户已被禁用
     */
    @ResponseBody
    @RequestMapping("/login")
    public String login(HttpSession session, String username, String password){
        UserVo userVo = indexService.getUser(username,password);
        String r ="1";
        if(userVo==null){
            r="0";
        }else if(userVo.getIsvalid()!=null && userVo.getIsvalid()!=1){
            r="2";
        }else {
            r = "1";
            session.setAttribute(WebContens.SESSION_UER,userVo);
        }
        return r;
    }

    @RequestMapping("/main")
    public String toMain(){
        return "/system/main/index";
    }

}
